<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app"></div>
    <script src="./libs/react.js"></script>
    <script src="./libs/react-dom.js"></script>
    <script src="./libs/babel.min.js"></script>
    <script type="text/babel">
      const { Component } = React;
      // 跨组件之间传参，在各个组件之间进行传递
      const mainContext = React.createContext();
      console.log(mainContext);
      const { Provider } = mainContext;

      class B extends Component {
        constructor(props) {
          super(props);
          this.state = {};
        }
        render() {
          console.log(this.context);
          return (
            <>
              <p>我是一个组件B</p>
            </>
          );
        }
      }
      B.contextType = mainContext; // 此时B组件会出现context值

      class App extends Component {
        constructor(props) {
          super(props);
          this.state = {};
        }
        static contextType = mainContext;
        render() {
          return (
            <>
              <B />
            </>
          );
        }
      }
      ReactDOM.render(
        <Provider value={{ title: "标题", name: "dada", color: "orange" }}>
          <App />
        </Provider>,
        document.getElementById("app")
      );
    </script>
  </body>
</html>
